home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / src_1218.zip / PPPFSM.H < prev    next >
C/C++ Source or Header  |  1991-09-21  |  6KB  |  222 lines

  1. #ifndef _PPPFSM_H
  2. #define _PPPFSM_H
  3.  
  4. #ifndef    _MBUF_H
  5. #include "mbuf.h"
  6. #endif
  7.  
  8. #ifndef    _PROC_H
  9. #include "proc.h"
  10. #endif
  11.  
  12. #ifndef    _IFACE_H
  13. #include "iface.h"
  14. #endif
  15.  
  16. #ifndef    _TIMER_H
  17. #include "timer.h"
  18. #endif
  19.  
  20.                 /* 00: serious internal problems */
  21.                 /* 01: interoperability problems */
  22.                 /* 02: state machine messages */
  23. #define PPP_DEBUG_RAW
  24. #define PPP_DEBUG_OPTIONS    0x08
  25. #define PPP_DEBUG_CHECKS(x)    if(PPPtrace & 0x40) trace_log(PPPiface,x);
  26. #define PPP_DEBUG_ROUTINES(x)    if(PPPtrace & 0x80) trace_log(PPPiface,x);
  27.  
  28. /* config packet header */
  29. struct config_hdr {
  30.     byte_t code;
  31. #define CONFIG_REQ     1
  32. #define CONFIG_ACK     2
  33. #define CONFIG_NAK     3
  34. #define CONFIG_REJ     4
  35. #define TERM_REQ     5
  36. #define TERM_ACK     6
  37. #define CODE_REJ     7
  38. #define PROT_REJ     8
  39. #define ECHO_REQ     9
  40. #define ECHO_REPLY    10
  41. #define DISCARD_REQ    11
  42. #define QUALITY_REPORT    12
  43.  
  44.     byte_t id;
  45.     int16 len;
  46. };
  47. #define CONFIG_HDR_LEN    4    /* Length of config packet header */
  48.  
  49.  
  50. /* config option header */
  51. struct option_hdr {
  52.     byte_t type;        /* protocol dependant types */
  53.     byte_t len;
  54. };
  55. #define OPTION_HDR_LEN    2    /* Length of option header */
  56.  
  57.  
  58. /* Supported Configuration Protocol index */
  59. enum {
  60.     Lcp,
  61.     Pap,
  62.     IPcp,
  63.     fsmi_Size
  64. };
  65.  
  66. struct fsm_s;        /* forward declaration */
  67.  
  68. /* Protocol Constants needed by State Machine */
  69. struct fsm_constant_s {
  70.     char *name;            /* Name of protocol */
  71.     int16 protocol;            /* Protocol number */
  72.     int16 recognize;        /* Config codes to use (bits) */
  73.  
  74.     byte_t fsmi;            /* Finite State Machine index */
  75.     byte_t try_req;            /* # tries for request */
  76.     byte_t try_nak;            /* # tries for nak substitutes */
  77.     byte_t try_terminate;        /* # tries for terminate */
  78.     int32 timeout;            /* Time for timeouts (milliseconds)*/
  79.  
  80.     /* To free structure */
  81.     void (*free)        __ARGS((struct fsm_s *fsm_p));
  82.  
  83.     /* Set negotiation to initial values */
  84.     void (*reset)        __ARGS((struct fsm_s *fsm_p));
  85.     /* When leaving Closed or Listen */
  86.     void (*starting)    __ARGS((struct fsm_s *fsm_p));
  87.     /* When entering Opened */
  88.     void (*opening)        __ARGS((struct fsm_s *fsm_p));
  89.     /* When leaving Opened */
  90.     void (*closing)        __ARGS((struct fsm_s *fsm_p));
  91.     /* When entering Closed or Listen (after termination) */
  92.     void (*stopping)    __ARGS((struct fsm_s *fsm_p));
  93.  
  94.     struct mbuf *(*makereq)    __ARGS((struct fsm_s *fsm_p));
  95.  
  96.     int (*request)        __ARGS((struct fsm_s *fsm_p,
  97.                     struct config_hdr *hdr,
  98.                     struct mbuf *bp));
  99.     int (*ack)        __ARGS((struct fsm_s *fsm_p,
  100.                     struct config_hdr *hdr,
  101.                     struct mbuf *bp));
  102.     int (*nak)        __ARGS((struct fsm_s *fsm_p,
  103.                     struct config_hdr *hdr,
  104.                     struct mbuf *bp));
  105.     int (*reject)        __ARGS((struct fsm_s *fsm_p,
  106.                     struct config_hdr *hdr,
  107.                     struct mbuf *bp));
  108. };
  109.  
  110. /* FSM states */
  111. enum {
  112.     fsmCLOSED,
  113.     fsmLISTEN,
  114.     fsmREQ_Sent,
  115.     fsmACK_Rcvd,
  116.     fsmACK_Sent,
  117.     fsmOPENED,
  118.     fsmTERM_Sent,
  119.     fsmState_Size
  120. };
  121.  
  122. /* State Machine Control Block */
  123. struct fsm_s {
  124.     byte_t state;            /* FSM state */
  125.     byte_t lastid;            /* ID of last REQ we sent */
  126.  
  127.     byte_t flags;
  128. #define PPP_ESCAPED    0x01
  129. #define PPP_TOSS    0x02
  130. #define FSM_PASSIVE    0x40    /* opened passive */
  131. #define FSM_ACTIVE    0x80    /* opened active */
  132.  
  133.     byte_t retry;            /* counter for timeouts */
  134.     byte_t try_req;            /* # tries for request */
  135.     byte_t try_terminate;        /* # tries for terminate */
  136.  
  137.     byte_t retry_nak;        /* counter for naks of requests */
  138.     byte_t try_nak;            /* # tries for nak substitutes */
  139.  
  140.     struct ppp_s *ppp_p;        /* the ppp we belong to */
  141.     struct timer timer;
  142.     struct fsm_constant_s *pdc;    /* protocol dependent constants */
  143.     void *pdv;            /* protocol dependent variables */
  144. };
  145.  
  146.  
  147. /* Link Phases */
  148. enum {
  149.     pppDEAD,        /* Waiting for physical layer */
  150.     pppLCP,            /* Link Control Phase */
  151.     pppAP,            /* Authentication Phase */
  152.     pppREADY,        /* Link ready for traffic */
  153.     pppTERMINATE,        /* Termination Phase */
  154.     pppPhase_Size
  155. };
  156.  
  157. /* PPP control block */
  158. struct ppp_s {
  159.     struct iface *iface;        /* pointer to interface block */
  160.  
  161.     byte_t phase;            /* phase of link initialization */
  162.     byte_t id;            /* id counter for connection */
  163.  
  164.     byte_t flags;
  165. #define PPP_AP_LOCAL    0x10    /* local authentication */
  166. #define PPP_AP_REMOTE    0x20    /* remote authentication */
  167.  
  168.     byte_t trace;            /* trace flags for connection */
  169.  
  170.     struct fsm_s fsm[fsmi_Size];    /* finite state machines */
  171.  
  172.     int32 upsince;            /* Timestamp when Link Opened */
  173.     char *peername;            /* Peername from remote (if any) */
  174.  
  175.     int32 OutTxOctetCount;        /* # octets sent */
  176.     int32 OutOpenFlag;        /* # of open flags sent */
  177.     int16 OutNCP[fsmi_Size];    /* # NCP packets sent by protocol */
  178.     int16 OutError;            /* # packets with error on send */
  179.     int16 OutMemory;        /* # alloc failures on send */
  180.  
  181.     int32 InRxOctetCount;        /* # octets received */
  182.     int32 InOpenFlag;        /* # of open flags */
  183.     int16 InNCP[fsmi_Size];        /* # NCP packets by protocol */
  184.     int16 InUnknown;        /* # unknown packets received */
  185.     int16 InChecksum;        /* # packets with bad checksum */
  186.     int16 InFrame;            /* # packets with frame error */
  187.     int16 InError;            /* # packets with other error */
  188.     int16 InMemory;         /* # alloc failures */
  189. };
  190. #define NULLPPP    (struct ppp_s *)0
  191.  
  192.  
  193. extern char *fsmStates[];
  194. extern char *fsmCodes[];
  195.  
  196. struct mbuf *htoncnf __ARGS((struct config_hdr *cnf, struct mbuf *data));
  197. int ntohcnf __ARGS((struct config_hdr *cnf, struct mbuf **bpp));
  198. int ntohopt __ARGS((struct option_hdr *opt, struct mbuf **bpp));
  199.  
  200. void fsm_no_action    __ARGS((struct fsm_s *fsm_p));
  201. int fsm_no_check    __ARGS((struct fsm_s *fsm_p,
  202.                 struct config_hdr *hdr,
  203.                 struct mbuf *bp));
  204.  
  205. void fsm_log    __ARGS((struct fsm_s *fsm_p, char *comment));
  206. void fsm_timer    __ARGS((struct fsm_s *fsm_p));
  207.  
  208. int fsm_send    __ARGS((struct fsm_s *fsm_p, byte_t code,
  209.             byte_t id, struct mbuf *data));
  210. int fsm_sendreq    __ARGS((struct fsm_s *fsm_p));
  211.  
  212. void fsm_proc    __ARGS((struct fsm_s *fsm_p, struct mbuf *bp));
  213.  
  214. void fsm_start    __ARGS((struct fsm_s *fsm_p));
  215. void fsm_down    __ARGS((struct fsm_s *fsm_p));
  216. void fsm_close    __ARGS((struct fsm_s *fsm_p));
  217.  
  218. void fsm_init    __ARGS((struct fsm_s *fsm_p));
  219. void fsm_free    __ARGS((struct fsm_s *fsm_p));
  220.  
  221. #endif /* _PPPFSM_H */
  222.